const db = require('../models')

class OrdercqRepositiories {
  async addNewOrdercq(ordercqData) {
    try {
      const newOrdercq = await db.OrdersCunqu.create(ordercqData);
      return newOrdercq;
    } catch (error) {
      throw error;
    }
  }

  async delOrdercqById(id) {
    const ordercq = await db.OrdersCunqu.findOne({ where: { id } });
    return ordercq ? (await db.OrdersCunqu.destroy(ordercq), true) : false;
  }

  async getOrdercqByCunId(id) {
    return await db.OrdersCunqu.findAll({ where: { id } });
  }

  async getAllOrdercqs() {
    try {
      return await db.OrdersCunqu.findAll();
    } catch (error) {
      console.log("error: ");
      console.log(error);
    }
  }

  async getOrdercqByQucode(quCode) {
    try {
      return await db.OrdersCunqu.findOne({ where: { quCode } });
    } catch (error) {
      throw error
    }
  }
}

module.exports = new OrdercqRepositiories